package experiment2_3;

/**
 * Date: 2023-04-23
 * Time: 15:48
 */

    public class Test {
        public static void main(String[] args) {
            Animal spider = new Spider();
            spider.walk();
            spider.eat();

            Cat cat = new Cat("Kitty");
            cat.walk();
            cat.play();
            cat.eat();
            System.out.println(cat.getName() + " eating?");
        }
    }

    abstract class Animal {
        protected String type;
        protected int legs;

        protected Animal(String type, int legs) {
            this.type = type;
            this.legs = legs;
        }

        public abstract void eat();

        public void walk() {
            System.out.println("用 " + legs + " 条腿走路");
        }
    }

    class Spider extends Animal {
        public Spider() {
            super("spider", 8);
        }

        public void eat() {
            System.out.println("spider eating");
        }
    }

    interface Pet {
        void setName(String name);


        String getName();

        void play();
    }


    class Cat extends Animal implements Pet {
        private String name;


        public Cat(String name) {
            super("cat", 4);
            this.name = name;
        }


        public Cat() {
            this("");
        }


        public void setName(String name) {
            this.name = name;
        }


        public String getName() {
            return name;
        }

        public void play() {
            System.out.println("Cat is playing");
        }


        public void eat() {
            System.out.println(name + " eating");
        }
    }

